package com.woniuxy.educationplatform.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.educationplatform.bean.QuesBean;
import com.woniuxy.educationplatform.bean.StudentBean;
import com.woniuxy.educationplatform.mapper.QuesMapper;
import com.woniuxy.educationplatform.service.IQuesService;
import com.woniuxy.educationplatform.util.PageDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional(readOnly = true)
@Service
public class QuesServiceImpl implements IQuesService {
    @Resource
    private QuesMapper quesMapper;

    @Override
    public List<QuesBean> findAll(QuesBean quesBean) {
        return quesMapper.findAll(quesBean);
    }

    @Override
    public QuesBean getOneById(Long id) {
        return quesMapper.getOneById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int addQuesBean(QuesBean quesBean) {
        return quesMapper.addQuesBean(quesBean);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateQuesBean(QuesBean quesBean) {
        return quesMapper.updateQuesBean(quesBean);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteQuesBean(Long id) {
        return quesMapper.deleteQuesBean(id);
    }




//    @Override
//    public PageDto findAllByParams(QuesBean quesBean, int pageNum, int pageSize) {
//        //页码非法则直接返回
//        if (pageNum <= 0) {
//            return null;
//        }
//        PageHelper.startPage(pageNum, pageSize);
//        List<QuesBean> data = quesMapper.findAllByParams(quesBean);
//        PageInfo<QuesBean> pageInfo = new PageInfo<>(data);
//
//        PageDto pageDto = new PageDto();
//        //返回一共多少条数据
//        pageDto.setTotal(pageInfo.getTotal());
//        //返会数据
//        pageDto.setData(data);
//        return pageDto;
//    }




    /*@Override
    public QuesBean getOneById(Long id) {
        return quesMapper.getOneById(id);
    }

    @Override
    public int addQuesBean(QuesBean quesBean) {
        return 0;
    }

    @Override
    public int updateQuesBean(QuesBean quesBean) {
        return 0;
    }

    @Override
    public int deleteQuesBean(Long id) {
        return 0;
    }


    @Override
    public List<QuesBean> findAllByParams(){
        QuesBean quesBean = new QuesBean();
        return quesMapper.findAllByParams(quesBean);
    }*/
}
